package java_thinking.unit_9._9_9;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2019-03-08 21:35
 */
interface Game {
    boolean move();
}
interface GameFactory {
    Game getGame();
}

class Checkers implements Game {
    private int move = 0;
    private static final int MOVES = 3;
    @Override
    public boolean move() {
        System.out.println("Checkers move"+move);
        return ++move !=MOVES;
    }
}
class CheckersFactory implements GameFactory {

    @Override
    public Game getGame() {
        return new Checkers();
    }
}

class Chess implements Game {
    private int move =0;
    private static final int MOVES = 4;
    @Override
    public boolean move() {
        System.out.println("Chess.move"+move);
        return ++move !=MOVES;
    }
}

class ChessFactory implements GameFactory{

    @Override
    public Game getGame() {
        return new Chess();
    }
}
class Games{
    public static void playGame(GameFactory factory){
        Game game = factory.getGame();
        while (game.move());
    }

    public static void main(String[] args) {
        Games.playGame(new CheckersFactory());
        Games.playGame(new ChessFactory());
    }
}